package my_xml;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class Test1 {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read("AdvancedCode\\src\\my_xml\\teacher-info.xml");
        Element rootElement = read.getRootElement();
        List<Element> elements = rootElement.elements();
        ArrayList<Teacher> teachers = new ArrayList<>();

        for (Element element : elements) {
            Attribute attribute = element.attribute("id");
            String id = attribute.getValue();
            Element nameElement = element.element("name");
            String name = nameElement.getText();
            Element ageElement = element.element("age");
            String age = ageElement.getText();
            Element infoElement = element.element("info");
            String info = infoElement.getText();
            teachers.add(new Teacher(id, name, Integer.parseInt(age), info));
        }
        System.out.println(teachers);
    }
}
